﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MyHealthOnline.Business;
using SD.LLBLGen.Pro.ORMSupportClasses;
using MyHealthOnline.Dal.Generated.CollectionClasses;

namespace MyHealthOnline.Specialist
{
    public partial class ClosedConsultations : System.Web.UI.Page
    {
        public ConsultCollection Consults
        {
            get
            {
                return ViewState["Consults"] as ConsultCollection;
            }
            set
            {
                ViewState["Consults"] = value;
            }
        }
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                SetGrid(PatientsConsults);
            }
        }

        private void SetGrid(ConsultCollection consults)
        {
            Consults = consults;
            grdClosedConsultationsPatients.DataSource = consults;
            grdClosedConsultationsPatients.DataBind();
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {

            var patientList = ConsultBusiness.FilterConsults(PatientsConsults,
                                txtSearchPatient.Text);

            SetGrid(patientList);
        }

        private ConsultCollection PatientsConsults
        {
            get
            {
                return ConsultBusiness.GetClosedConsults();
            }
            
        }

        protected void grdClosedConsultationsPatients_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "View")
            {
                int index=Convert.ToInt32(e.CommandArgument);
                int id = Convert.ToInt32(grdClosedConsultationsPatients.DataKeys[index].Value);
                Response.Redirect(string.Format("~/Specialist/ViewConsult.aspx?ConsultId={0}", id));
            }
        }
    }
}